package net.da.tools;

import java.util.ArrayList;
import java.util.List;

public class MethodDescriptor implements Cloneable {

	private static final String EMPTY_STRING = "";

	private String accessQualifier;

	private TypeDescriptor returnType;

	private String name;

	private boolean abstractMrthod;

	private List<Parameter> params;
	
	private List<ClassDescriptor> usedClasses;

	private boolean constructor;

	private MethodBody body;

	public MethodDescriptor() {

		accessQualifier = EMPTY_STRING;
		returnType = null;
		name = EMPTY_STRING;
		abstractMrthod = false;
		params = new ArrayList<Parameter>();
		usedClasses = new ArrayList<ClassDescriptor>();
		constructor = false;
		body = null;
	}

	public List<ClassDescriptor> getUsedClasses() {

		List<ClassDescriptor> usedClassesClone = new ArrayList<ClassDescriptor>(
				usedClasses);
		if (isHasParams()) {
			for (Parameter param : params) {
				ClassDescriptor paramClass;
				if (!param.getType().isPrimitive()) {
					paramClass = param.getType().getClassDescriptor();
					usedClassesClone.add(paramClass);
				}
			}
		}
		if (isHasReturnType()) {
			ClassDescriptor returnClass;
			if (!returnType.isPrimitive()) {
				returnClass = returnType.getClassDescriptor();
				usedClassesClone.add(returnClass);
			}
		}
		return usedClassesClone;
	}

	public void addParam(Parameter param) {
		params.add(param);
	}

	public boolean isHasParams() {
		return !params.isEmpty();
	}

	public boolean isHasReturnType() {
		return returnType != null;
	}

	public boolean isAbstractMethod() {
		return abstractMrthod;
	}

	public void setAbstractMrthod(boolean abstractMrthod) {
		this.abstractMrthod = abstractMrthod;
	}

	public String getAccessQualifier() {
		return accessQualifier;
	}

	public void setAccessQualifier(String accessQualifier) {
		this.accessQualifier = accessQualifier;
	}
	
	public MethodBody getBody() {
		return body;
	}

	public void setBody(MethodBody body) {
		this.body = body;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public TypeDescriptor getReturnType() {
		return returnType;
	}

	public void setReturnType(TypeDescriptor returnType) {
		this.returnType = returnType;
	}

	public List<Parameter> getParams() {
		return params;
	}

	public boolean isConstructor() {
		return constructor;
	}

	public void setConstructor(boolean constructor) {
		this.constructor = constructor;
	}

	@Override
	protected Object clone() throws CloneNotSupportedException {
		// TODO Auto-generated method stub
		return super.clone();
	}

}
